Add --in-git-diff convenience option - #628
Open
ychampion wants to merge 1 commit into
Open
Conversation
Add the maintainer-requested Git revision adapter while reusing the existing unified-diff filter. Keep explicit patch-file input unchanged and cover nested workspaces plus invalid revisions. Constraint: Use the Git CLI requested in sourcefrog#245 without adding a dependency. Rejected: git2-rs | Unnecessary build weight for a single diff invocation. Confidence: high Scope-risk: narrow Directive: Keep --in-diff and --in-git-diff mutually exclusive. Tested: Focused diff tests; strict all-target/all-feature Clippy; 429/431 all-feature nextest cases; release build and nested-workspace smoke; rustfmt; cargo-machete; diff checks. Not-tested: mdBook linkcheck and typos binaries are unavailable locally; two permission-denied tests fail as root identically on upstream.
Contributor
There was a problem hiding this comment.
Pull request overview
Adds a new CLI filter option, --in-git-diff REVISION, to let cargo-mutants compute a diff by invoking git diff directly and then reuse the existing diff-based mutant filtering logic (including behavior for nested workspaces and invalid revisions).
Changes:
- Add
--in-git-diff REVISIONCLI option and wire it into mutant filtering flow. - Implement
diff_filter_git()to rungit diffand feed its output into the existing diff filter. - Add tests plus user-facing documentation updates (book + NEWS).
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/main.rs | Adds integration tests for filtering via git diff, including nested workspace and invalid revision handling. |
| src/main.rs | Introduces the --in-git-diff argument and applies it in the main filtering pipeline. |
| src/in_diff.rs | Adds diff_filter_git() and a new DiffFilterError::Git error variant for git invocation failures. |
| NEWS.md | Documents the new --in-git-diff option in Unreleased notes. |
| book/src/in-diff.md | Updates the user guide to describe --in-git-diff and its interaction with --in-diff. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| workspace_root: &Utf8Path, | ||
| revision: &str, | ||
| ) -> Result<Vec<Mutant>, DiffFilterError> { | ||
| let output = Command::new("git") |
Comment on lines
+2042
to
+2044
| &["add", "."], | ||
| &["commit", "--quiet", "--message", "baseline"], | ||
| ] { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
--in-git-diff REVISIONas a convenience wrapper aroundgit diffWhy
This avoids writing a temporary patch file when testing changes from a branch or pull request.
Closes #245.
Validation
cargo test --locked diff -- --nocapturecargo clippy --all-targets --all-features --locked -- -D warningscargo fmt --all -- --checkcargo build --release --lockedcargo machete